package com.rdc.soulmatemusicplayer.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.TextView;

import com.rdc.soulmatemusicplayer.R;
import com.rdc.soulmatemusicplayer.bean.Song;
import com.rdc.soulmatemusicplayer.util.MusicUtils;

import java.util.List;

/**
 * @author Soul Mate
 * @file
 * @brief 音乐列表adapter
 * @date 创建日期  2021-04-15 0:23
 */

public class MusicListAdapter extends BaseAdapter
{
	private int mPlayingPosition;

	private Context mContext;
	private List<Song> list;


	public MusicListAdapter (Context context, List<Song> list)
	{
		this.mContext=context;
		this.list = list;
	}


	public void setPlayingPosition(int position)
	{
		mPlayingPosition = position;
	}



	@Override
	public int getCount()
	{
		return MusicUtils.sMusicList.size();
	}

	@Override
	public Object getItem(int position)
	{
		return MusicUtils.sMusicList.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		final ViewHolder holder;

		if (convertView == null)
		{
			convertView= LayoutInflater.from(mContext).inflate(R.layout.song_list_item, null);
			holder = new ViewHolder();
			holder.title =  convertView.findViewById(R.id.tv_song_list_title);
			holder.artist = convertView.findViewById(R.id.tv_song_list_artist);
			holder.time = convertView.findViewById(R.id.tv_song_list_time);
			convertView.setTag(holder);
		} else
		{
			holder = (ViewHolder) convertView.getTag();
		}

//		Bitmap icon = MusicIconLoader.getInstance()
//				.load(MusicUtils.sMusicList.get(position).getImage());
//		holder.icon.setImageBitmap(icon);

		holder.title.setText(MusicUtils.sMusicList.get(position).title);
		holder.artist.setText(MusicUtils.sMusicList.get(position).artist);

		int length = list.get(position).length;
		String time = MusicUtils.formatTime(length);//时间转换
		holder.time.setText(time);

		return convertView;
	}

	static class ViewHolder
	{
		TextView title;
		TextView artist;
		TextView time;
//		ImageView icon ;
	}

}
